package net.kangyee.eventmanager.commands;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;

import net.kangyee.eventmanager.EventManager;
import net.kangyee.eventmanager.util.MessageManager;

public class CmdTphere extends EventManagerCommand {
	
	private EventManager plugin;
	
	public CmdTphere(EventManager plugin){
		this.plugin = plugin;
	}
	
	public void onCommand(Player player, String[] args){
        if(args.length == 2){
        	if(!plugin.playerStateChecker(player,args[1])){
        		return;
        	}
        	Player targetPlayer = Bukkit.getPlayer(args[1]);
            targetPlayer.getPlayer().teleport(this.getLocation(player));
            MessageManager.sendNormalMessage(player, "玩家&6" + player.getName() + "&f被传送到你所在的位置");
        	MessageManager.sendAdminMessage(targetPlayer, "你被管理员传送到他所在的位置");   		
        	return;
        }else{
        	Location loc = this.getLocation(player);
        	for(Player localPlayer : plugin.regPlayers.keySet()){
        		localPlayer.getPlayer().teleport(loc);
        		MessageManager.sendAdminMessage(localPlayer, "你被管理员传送到他所在的位置");   	
            }
        	MessageManager.sendNormalMessage(player, "所有参加活动的玩家被传送到你所在的位置");
        	return;
        }
	}
	
	private Location getLocation(Player player){
		double px = player.getPlayer().getLocation().getX();
        double py = player.getPlayer().getLocation().getY();
        double pz = player.getPlayer().getLocation().getZ();
        World pworld = player.getPlayer().getLocation().getWorld();
        return new Location(pworld, px, py, pz);
	}

	public String getCmdName(){
		return "tphere";
	}

	public String getArgs(){
		return "[游戏名]";
	}
	
	public int getMaxArgs(){
		return 2;
	}

	public int getMinArgs(){
		return 1;
	}

	public String getPermission(){
		return "eventmanager.admin." + getCmdName();
	}

	public boolean getStateRequire(){
		return true;
	}
	
	public boolean getRegPCRequire() {
		return true;
	}
}
